//
//  database.h
//  magazzino
//
//  Created by Vito on 17/11/14.
//  Copyright (c) 2014 Vito. All rights reserved.
//

#ifndef _DATABASE_H_
#define _DATABASE_H_


#include <string>
#include <vector>
#include <sqlite3.h>
#include <list>
using namespace std;

typedef struct _Item {
    double price;
    string description;
    double qnt;
    string code;
}  Item;

typedef Item* pItem ;

class Database
{
public:
    Database(const char* filename);
    ~Database();
    
    bool open(const char* filename);
    bool createItemsTable();

    bool insertItems(vector<Item> items);
    bool updateItem(char* code, int qnt);
    bool insertItem(char* code, char*desc, int qnt);

    Item loadItem(string code);
    vector<Item> loadItems();
    
    void cleanItemsTable();

    void close();
    
private:
    sqlite3 *database;
    bool exist(string code);
    vector<vector<string> > query(char* query);

};

#endif // _DATABASE_H_


